
load('summary_data/figA6.rda')

g1 = ggplot(out_summ[!grepl('^N', variable) &
                       as.numeric(nat_quant) != 0.85],
            aes(nat_quant, value * 100, color = variable, group = variable)) +
  geom_point() +
  geom_line() +
  theme_light() +
  geom_hline(yintercept = 0,
             linetype = 'dashed',
             color = 'grey') +
  labs(
    x = element_blank(),
    y = element_blank(),
    color = element_blank(),
    title = '          Raw Contribution Rates'
  ) +
  scale_color_manual(
    values = c(
      'blue',
      'deepskyblue',
      'darkslateblue',
      'chocolate1',
      'brown1',
      'darkred'
    )[c(4:6, 1:3)],
    breaks = c('obama12', 'clinton', 'biden', 'romney', 'trump16', 'trump20')[c(4:6, 1:3)],
    labels = c(
      'Obama \'12',
      'Clinton \'16',
      'Biden \'20',
      'Romney \'12',
      'Trump \'16',
      'Trump \'20'
    )[c(4:6, 1:3)]
  ) +
  theme(text = element_text(face = 'bold', size = 10)) +
  scale_y_continuous(
    breaks = c(0:9),
    labels = scales::label_percent(scale = 1),
    position = "right"
  ) +
  theme(legend.position = 'bottom', legend.margin = margin(c(5, 5, 5, -5))) +
  theme(axis.text.x = element_text(
    angle = 25,
    vjust = .85,
    hjust = 0.5,
    size = 7
  )) +
  scale_x_discrete(labels = x_l)

g2 = ggplot(out_summ2[!grepl('^N', variable) &
                        as.numeric(nat_quant) != 0.85],
            aes(nat_quant, value, color = variable, group = variable)) +
  geom_point() +
  geom_line() +
  theme_light() +
  geom_hline(yintercept = 0,
             color = 'grey',
             linetype = 'dashed') +
  labs(
    x = element_blank(),
    y = element_blank(),
    color = element_blank(),
    title = '          Raw Per-Capita Dollars'
  ) +
  scale_color_manual(
    values = c(
      'blue',
      'deepskyblue',
      'darkslateblue',
      'chocolate1',
      'brown1',
      'darkred'
    )[c(4:6, 1:3)],
    breaks = c('obama12', 'clinton', 'biden', 'romney', 'trump16', 'trump20')[c(4:6, 1:3)],
    labels = toupper(c('d12', 'd16', 'd20', 'r12', 'r16', 'r20'))[c(4:6, 1:3)]
  ) +
  theme(text = element_text(face = 'bold', size = 10)) +
  theme(legend.position = 'right', legend.margin = margin(c(5, 5, 5, -5))) +
  theme(axis.text.x = element_text(
    angle = 25,
    vjust = .85,
    hjust = 0.5,
    size = 7
  )) +
  scale_x_discrete(labels = x_l) +
  scale_y_continuous(labels = scales::label_dollar(), position = "right")

out = plot_grid(
  g1 + theme(legend.position = 'none'),
  g2 + theme(legend.position = 'none'),
  labels = str_c('(', LETTERS[1:2], ')'),
  nrow = 2
) %>%
  plot_grid(get_legend_35(
    g1 + theme(legend.margin = margin(c(-10, 0, 0, 0))) +
      guides(color = guide_legend(nrow = 1, byrow = F))
  ),
  rel_heights = c(1, .05),
  nrow = 2)

ggsave(
  filename = 'figures/figA6.pdf',
  plot = out,
  width = 8,
  height = 7,
  units = 'in'
)
